﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UITournament.FactoryMethod;

namespace UITournament
{
    public abstract class Person: ICreatable
    {
        private string firstName;
        private string lastName;

        public string FirstName
        {
            get { return firstName; }
            set
            {
                try
                {
                    if (Validation.ValidatePersonName(value))
                    {
                        firstName = value;
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                catch (Exception ex)
                {
                    throw new InvalidNameException("The entered name is not valid!\nAllowed symbols are: A-Z (case insensitive) and -, starting with letter.", ex);
                }
            }
        }

        public string LastName
        {
            get { return lastName; }
            set
            {
                try
                {
                    if (Validation.ValidatePersonName(value))
                    {
                        lastName = value;
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                catch (Exception ex)
                {
                    throw new InvalidNameException("The entered name is not valid!\nAllowed symbols are: A-Z (case insesitive) and -, starting with letter.", ex);
                }
            }
        }

        protected Person(string firstName, string lastName)
        {
            this.FirstName = firstName;
            this.LastName = lastName;
        }

        public abstract void Create();
    }
}
